package com.yqg.protection.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yqg.protection.common.Result;
import com.yqg.protection.entity.WarnJh;
import com.yqg.protection.service.IWarnJhService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * WarnJhController 前端控制器
 * @author zxf
 * @since 2025-08-30
 */
@RestController
@RequestMapping("/warn-jh")
public class WarnJhController {

    @Resource
    private IWarnJhService warnJhService;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody WarnJh warnJh) {
        return Result.success(warnJhService.saveOrUpdate(warnJh));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        WarnJh warnJh =warnJhService.getById(id);
        return Result.success(warnJhService.saveOrUpdate(warnJh));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<WarnJh> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<WarnJh> list=  warnJhService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(warnJhService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        QueryWrapper<WarnJh> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        queryWrapper.orderByDesc("id");
        return Result.success(warnJhService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    @GetMapping("/getInfo")
    public Result getInfo(@RequestParam Long equipmentInputStoreId,
                          @RequestParam String warnTime) {
        LambdaQueryWrapper<WarnJh> warnJhLambdaQueryWrapper = new LambdaQueryWrapper<>();
        warnJhLambdaQueryWrapper.eq(WarnJh::getEquipmentInputStoreId, equipmentInputStoreId);
        warnJhLambdaQueryWrapper.eq(WarnJh::getSendTime, warnTime);
        return Result.success(warnJhService.getOne(warnJhLambdaQueryWrapper));
    }
}

